package com.youku.component.report;

/**
 * html格式的测试报告
 * 
 * @author loda
 *
 */
public class HtmlTestReport extends AbstractTestReport {

	@Override
	public String format() {
		if (records.size() == 0) {
			return "<b>沒有测试用例</b>";
		}
		StringBuilder builder = new StringBuilder(
				"<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>测试结果报告</title><style>* {	font-family: \"微软雅黑\";	margin: 0px auto;}.container {	width: 1024px;}.header {	padding: 30px;}.header, .footer {	text-align: center;}.header>.titler {	font-size: 2em;}.upper, .lower {	border-radius: 15px;	padding: 20px;	background-color: #eee;	margin-bottom: 50px;}.upper table {	width: 85%;}.upper table td {	width: 45%;	font-size: 1.1em;}.success {color: green;}.failure {color: red;}.lower {	min-height: 200px;}.inner-box{	width:100%;	text-align:center;}.inner-box th{	font-size:14px;}.inner-box td{	font-size:14px;}.message{	max-width:200px;}.keyword {	color: red;}</style></head><body><div class=\"container\"><div class=\"header\"><span class=\"titler center-element\">测试报告</span></div><div class=\"mainer\"><div class=\"upper\"><table><tbody><tr><td>测试项目</td><td>")
						.append(projectId).append("</td></tr><tr><td>测试结果</td><td>").append(result())
						.append("</td></tr><tr><td>总数量</td><td>").append(totalSize())
						.append("</td></tr><tr><td>成功数</td><td class=\"success\">").append(success())
						.append("</td></tr><tr><td>失败数</td><td class=\"failure\">").append(fail())
						.append("</td></tbody></table></div>");

		builder.append(
				"<div class=\"lower\"><table class=\"inner-box\"><thead><tr><th>用例组</th><th>用例</th><th>状态</th><th class=\"message\">信息</th><th>执行时间</th></tr></thead><tbody>");

		for (TestRecord record : records) {
			builder.append("<tr><td>").append(record.getSuiteId()).append("</td><td>").append(record.getCaseId())
					.append("</td><td class=\"").append(record.statusForEn()).append("\">").append(record.statusForCn())
					.append("</td><td class=\"message\">").append(record.getMessage()).append("</td><td>")
					.append(record.getCreatetime()).append("</td></tr>");
		}

		builder.append(
				"</tbody></table></div><div class=\"footer\"><span class=\"author\">dev by jonathan loda</span></div></div></body></html>");

		return builder.toString();
	}

}
